#!/bin/bash

if [ ! -d "$HOME/.rustup" ]; then
    curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
fi

echo "INFO: Installing cargo-binutils"
cargo install cargo-binutils
if [ $? -ne 0 ]; then
    echo "ERROR: Installing cargo-binutils failed!"
    exit 1
fi

echo "INFO: Installing rustup toolchain nightly"
rustup toolchain install nightly
if [ $? -ne 0 ]; then
    echo "ERROR: Installing rustup toolchain nightly failed!"
    exit 1
fi

# rustup default nightly

# echo "INFO: Adding rustup component rust-src"
# rustup component add rust-src
# if [ $? -ne 0 ]; then
#     echo "ERROR: Adding rustup component rust-src failed!"
#     exit 1
# fi

# echo "INFO: Adding rustup component llvm-tools"
# rustup component add llvm-tools
# if [ $? -ne 0 ]; then
#     echo "ERROR: Adding rustup component llvm-tools failed!"
#     exit 1
# fi

echo "INFO: Installing qemu-system-x86_64 for debian"
sudo apt install -y qemu-system-x86
if [ $? -ne 0 ]; then
    echo "ERROR: Installing qemu-system-x86_64 for debian failed!"
    exit 1
fi